<template>
  <div>
    <van-nav-bar
      title="欢迎登录"
      right-text="去注册"
      @click-right="$router.push('/register')"
    />
    <div class="content">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          label="用户名"
          placeholder="用户名"
          maxlength="16"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          maxlength="18"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
<script>
import {reqLogin} from '@/api/index'
export default{
  data () {
    return {
      username: 'admin',
      password: '123',
    }
  },
  methods:{
    async onSubmit(values) {
      console.log('submit', values);
      const res = await reqLogin(values)
      console.log(res);
      if(res.status === 200){
        this.$router.replace('/personal')
      }else{
        this.$toast(res.msg)
      }
    },
  }
}
</script>
<style lang='less' scoped>
.content{
  margin: 100px 0 0 0;
}
</style>